package com.atguigu.day03;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.KeyedProcessFunction;
import org.apache.flink.util.Collector;
import scala.Int;

public class Example9 {
    public static void main(String[] args) throws Exception{
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        env
                .fromElements("white","black","gray")
                .keyBy(r -> 1)
                .process(new KeyedProcessFunction<Integer, String, String>() {
                    //来一条数据触发一次调用
                    @Override
                    public void processElement(String in, Context ctx, Collector<String> out) throws Exception {

                        if (in.equals("white")){
                            out.collect(in);
                        }else if (in.equals("black")){
                            out.collect(in);
                            out.collect(in);
                        }

                    }
                })
                .print();



        env.execute();

    }
}
